package com.p900.website.service.impl;

import com.p900.commons.domain.Advertisement;
import com.p900.website.repository.AdvertisementRepository;
import com.p900.website.service.AdvertisementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.prefs.AbstractPreferences;

/**
 * Created by lenovo on 2015/5/8.
 */
@Service
public class AdvertisementServiceImpl implements AdvertisementService {

    @Autowired
    private AdvertisementRepository advertisementRepository;

    @Override
    public Advertisement findAdvertisement(Long id) {
        Assert.notNull(id, "id is null");
        return advertisementRepository.findOne(id);
    }

    @Override
    public Page<Advertisement> findAll(Pageable pageable) {
        return advertisementRepository.findAll(pageable);
    }

    @Override
    public List<Advertisement> findByStatus(Integer status) {
        return advertisementRepository.findByStatus(status);
    }

    @Override
    public Advertisement save(Advertisement advertisement) {
        return advertisementRepository.save(advertisement);
    }

    @Override
    public void delete(@NotNull(message = "id is null") Long id) {
        advertisementRepository.delete(id);
    }
}
